package com.milhouz.quizzdroid.bean;

import android.database.Cursor;
import android.os.Parcel;
import android.os.Parcelable;

import com.milhouz.quizzdroid.db.QuizzDroidConstants;
import com.milhouz.quizzdroid.exception.DatabaseRequestException;

public class Category implements Parcelable {

	private int mId;
	private String mLabel;

	public Category() {
	}

	public Category(final Cursor cursor) throws DatabaseRequestException {
		if (cursor != null && cursor.moveToFirst()) {
			mId = cursor.getInt(cursor.getColumnIndex(QuizzDroidConstants.ID));
			mLabel = cursor.getString(cursor.getColumnIndex(QuizzDroidConstants.COLUMN_NAME_LABEL));
		} else {
			throw new DatabaseRequestException("Category cursor null or empty");
		}
	}

	public int getId() {
		return mId;
	}

	public String getLabel() {
		return mLabel;
	}

	@Override
	public void writeToParcel(Parcel parcel, int flag) {
		parcel.writeInt(mId);
		parcel.writeString(mLabel);
	}

	public static final Creator<Category> CREATOR = new Creator<Category>() {
		@Override
		public Category createFromParcel(Parcel source) {
			Category c = new Category();
			c.mId = source.readInt();
			c.mLabel = source.readString();
			return c;
		}

		@Override
		public Category[] newArray(int arg0) {
			return null;
		}
	};

	@Override
	public int describeContents() {
		return 0;
	}

}
